﻿using System;
using System.Data;

using BLL;
using Model;
using Utility;

namespace EvaluationSystem
{
    public partial class Afford : System.Web.UI.Page
    {
        private PaymentBLL payBll = new PaymentBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            ((SiteSystemMaster)Master).InitMenu();
            ((SiteSystemMaster)Master).li1.Attributes.Add("class", "hover ccc");
            ((SiteSystemMaster)Master).b_hmenu1.Style.Clear();
            ((SiteSystemMaster)Master).b_hmenu2.Style.Add("display", "none");
            ((SiteSystemMaster)Master).b_hmenu3.Style.Add("display", "none");
            ((SiteSystemMaster)Master).s_menu1_2.Style.Add("COLOR", "#147ab8");
            ((SiteSystemMaster)Master).s_menu1_2.Style.Add("TEXT-DECORATION", "none"); 

            /*判断是否是管理员身份*/
            if (Session["username"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script>alert('请先登录系统!');top.location.href='../System/Login.aspx';</script>");
                return;
            }
            else
            {
                if (!IsPostBack)
                {
                    lblActivityName.Text = Request["actnm"].ToString();
                }
            }        
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                int activityId = int.Parse(Request["actid"].ToString());

                int count = int.Parse(txtAvailablecount.Text.Trim());//次数
                float money = float.Parse(txtMoney.Text.Trim());//金额            

                if (payBll.AddPayment(activityId, money, count) != -1)
                {
                    //正常
                }
                else
                {
                }

                //产生GUID 分配企业。
                for (int i = 0; i < count; i++)
                {
                    string guidNew = GenerateGuid.NewGuidNo().Substring(0, 8);
                    GuidNo guidObject = new GuidNo();
                    guidObject.GuidStr = guidNew;
                    guidObject.ActivityId = activityId;
                    guidObject.CreateTime = DateTime.Now;
                    guidObject.Guid_status = 0;
                    GuidBLL guidBLL = new GuidBLL();
                    guidBLL.Add(guidObject);
                }

                ActivityBLL aBll = new ActivityBLL();
                DataSet dsEUsrInfo = aBll.GetEUsrInfoByActivityId(Int32.Parse(Request.QueryString["actid"]));
                MessageBox.ShowAndRedirect(this, "续费成功", "ActivityList.aspx?users_id=" + dsEUsrInfo.Tables[0].Rows[0][0].ToString());
            }
            catch (Exception ex)
            {
                MessageBox.ShowAndRedirect(this, "续费失败！" + ex.Message, "EnterpriseUserList.aspx");
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            ActivityBLL aBll = new ActivityBLL();
            DataSet dsEUsrInfo = aBll.GetEUsrInfoByActivityId(Int32.Parse(Request.QueryString["actid"]));
            Response.Redirect("ActivityList.aspx?users_id=" + dsEUsrInfo.Tables[0].Rows[0][0].ToString());
        }

    }
}